﻿@{
    Layout = null;
}
@model ElingOA6_Admin_DSJCJ.Model.HRDept
<!DOCTYPE html>

<html>
@Html.Partial("LoadPanelPartial")
<head>
    <title>DeptContent</title>
      @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/regex.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/PageCommon.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme },
                new StyleSheet { ExtensionType = ExtensionType.GridView, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)

    <script type="text/javascript">
        $(function () {
            $("#toolMenu").smartFloat();
        });

        function OnBeginCallback(s, e) {
            e.customArgs["command"] = e.command;
            e.customArgs["DeptNo"] = $('#hidDeptNo').val();
        }



        function MenuTop_emClick(source, e) {
            switch (e.item.name) {
                case "btnSave":
                    {


                        //保存

                        save();
                        break;
                    }
                case "btnAddSame":
                    {
                        //增同级
                        var parentDeptNo = $('#hidParentDeptNo').val();

                        window.location.href = rootPath + "/Admin/Dept/DeptContent?deptNo=" + parentDeptNo + "&addType=T";

                        break;
                    }
                case "btnAddNext":
                    {
                        //增下级
                        var deptno = $('#hidDeptNo').val();

                        window.location.href = rootPath + "/Admin/Dept/DeptContent?deptNo=" + deptno + "&addType=X";

                        break;
                    }
                case "btnSeqSameLevel":
                    {
                        //同级部门排序
                        seqSameLevel();
                        break;
                    }
                case "btnDelete":
                    {
                        //删除
                        var deptno = $('#hidDeptNo').val();
                        if (deptno == "") {
                            alert("请选择删除的部门!");
                        } else {
                            if (confirm("确定删除?")) {
                                lpModal.Show();
                                $.ajax({
                                    type: 'POST',
                                    url: rootPath + '/Admin/Dept/DelDept',
                                    data: { deptNo: deptno },
                                    success: function (result) {
                                        lpModal.Hide();
                                        if (result == "ok") {
                                            alert("删除成功");
                                            window.parent.location.href = rootPath+"/Admin/Dept";
                                        }
                                        else if (result == "existsEmp") {
                                            alert("无法删除：部门存在人员，请先删除相关人员");
                                        }
                                        if (result == "error") {
                                            alert("删除失败");
                                        }
                                        if (result == "") {
                                            alert("参数错误");
                                        }
                                    }
                                });
                            }
                        }

                        break;
                    }
            }
        }
        /*同级部门排序*/
        function seqSameLevel() {
            var deptNo = tbDeptNo.GetText();
            var url = rootPath + "/Admin/Dept/DeptSeq?deptNo=" + deptNo;
            var returnValue = window.showModalDialog(url, 'depttopseq', 'dialogWidth:700px;dialogHeight:500px');
            if (typeof (returnValue) != "undefined") {
                if (returnValue == "SUCCESS") {
                    var keyFocuse = deptNo;
                    parent.refreshLevelNode(keyFocuse);
                }

            }

        }
        //保存
        function save() {
            var deptNo = tbDeptNo.GetText();
            var deptName = tbDeptName.GetText();
            var seq = tbSeq.GetText();

            if (pd(deptNo, deptName, seq)) {
                if (gvEditing.GetVisibleRowsOnPage() == 0) {
                    lpModal.Hide();
                    alert("请增加岗位");
                } else {
                    var type = "add";
                    var hidDeptNo = $('#hidDeptNo').val();
                    if (hidDeptNo != "") {
                        type = "edit";
                    }

                    if (type == "add") {
                        $.ajax({
                            type: 'POST',
                            url: rootPath + '/Admin/Dept/ExistsDept',
                            data: { deptNo: deptNo },
                            success: function (result) {
                                if (result == "Y") {
                                    lpModal.Hide();
                                    tbDeptNo.SetErrorText("部门编号已经存在");
                                    tbDeptNo.SetIsValid(false);
                                } else if (result == "N") {
                                    save1(deptNo, deptName, seq, type);
                                }
                                else {
                                    lpModal.Hide();
                                    alert("部门编号判断错误");
                                }
                            }
                        });
                    } else {
                        save1(deptNo, deptName, seq, type);
                    }

                }


            } else {
                lpModal.Hide();
            }

        }

        // 保存
        function save1(deptNo, deptName, seq, type) {
            var parDeptNo = $('#hidParentDeptNo').val();
            var deptProp = ddlDeptProp.GetValue();
            var isAgency = rbIsAgency.GetValue();
            var chargeLeader = $('#hidChargeLeader').val();
            var fDeptShorName = FDeptShorName.GetText();
            var isReportPlanSummary = FIsReportPlanSummary.GetValue();
            var isCheckSystem = FIsCheckSystem.GetValue();
            lpModal.Show();
            $.ajax({
                type: 'POST',
                url: rootPath + '/Admin/Dept/DeptSave',
                data: { deptNo: deptNo, deptName: deptName, seq: seq, type: type, parDeptNo: parDeptNo, deptProp: deptProp, isAgency: isAgency, chargeLeader: chargeLeader, FDeptShorName: fDeptShorName, isReportPlanSummary: isReportPlanSummary, isCheckSystem: isCheckSystem },
                success: function (result) {
                    if (result == "ok") {
                        alert("保存成功");
                        if (type == "edit") {
                            parent.refreshNodeName(deptName);
                            lpModal.Hide();
                        } else {
                            window.parent.location.href = rootPath + "/Admin/Dept";
                        }

                    } else if (result == "error") {
                        alert("保存失败");
                    } else {
                        alert("参数错误");
                    }
                }
            });

        }

        //判断
        function pd(deptNo, deptName, seq) {
            var bl = true;
            if (deptNo == null || ASPxClientUtils.Trim(deptNo) == "") {
                tbDeptNo.SetErrorText("请填写部门编号");
                tbDeptNo.SetIsValid(false);
                bl = false;
            }

            if (deptName == null || ASPxClientUtils.Trim(deptName) == "") {
                tbDeptName.SetErrorText("请填写部门名称");
                tbDeptName.SetIsValid(false);
                bl = false;
            }

            if (seq == null || ASPxClientUtils.Trim(seq) == "") {
                tbSeq.SetErrorText("请填写顺序");
                tbSeq.SetIsValid(false);
                bl = false;
            } else {
                if (!isNumeric(seq)) {
                    tbSeq.SetErrorText("顺序必须是整数!");
                    tbSeq.SetIsValid(false);
                    bl = false;
                }
            }


            return bl;
        }

        //分管领导选择确定
        function EmpOK(v, n) {
            $('#hidChargeLeader').val(v);
            tbChargeLeader.SetText(n);
            pcModalMode.Hide();
        }

        //分管领导选择取消
        function EmpCancel() {
            pcModalMode.Hide();
        }

        //增加岗位
        function positionAdd() {
            var deptno = $('#hidDeptNo').val();
            if (deptno == "") {
                $("#popPositionContent").attr("src", rootPath + "/Admin/Dept/PositionEdit");
            } else {
                $("#popPositionContent").attr("src", rootPath + "/Admin/Dept/PositionEdit?deptno=" + deptno);
            }
            positionModalMode.Show();
        }

        //修改岗位
        function positionEdit(positionNo) {
            var deptno = $('#hidDeptNo').val();
            if (deptno == "") {
                $("#popPositionContent").attr("src", rootPath + "/Admin/Dept/PositionEdit?positionNo=" + positionNo);
            } else {
                $("#popPositionContent").attr("src", rootPath + "/Admin/Dept/PositionEdit?positionNo=" + positionNo + "&deptno=" + deptno);
            }
            positionModalMode.Show();
        }

        //删除岗位
        function positionDel(positionNo) {
            if (confirm("确定删除?")) {
                var deptno = $('#hidDeptNo').val();
                $.ajax({
                    type: 'POST',
                    url: rootPath + '/Admin/Dept/DelPosition',
                    data: { deptNo: deptno, positionNo: positionNo },
                    success: function (resutl) {
                        if (resutl == "ok") {
                            alert("删除成功");
                            gvEditing.Refresh();
                        }
                        else if (resutl == "no") {
                            alert("数据部存在");
                        }
                        else if (resutl == "error") {
                            alert("删除失败");
                        }
                        else if (resutl == "") {
                            alert("参数错误!");
                        }
                    }
                });
            }

        }

        //岗位增加修改确定
        function positionOK() {
            alert("保存成功!");
            positionModalMode.Hide();
            gvEditing.Refresh();
        }

        //岗位增加修改取消
        function positonCancel() {
            positionModalMode.Hide();
        }
        function ChargeLeader_ButtonClick(s, e) {
            switch (e.buttonIndex) {
                case 0:
                    pcModalMode.Show();
                    break;

            }
        }

    </script>

</head>
<body>
   @using (Html.BeginForm("Save", "Dept", FormMethod.Post, new { id = "form1", @class = "edit_form" }))
    { 
        <div class="floatToolMenu" id="toolMenu">
            @Html.DevExpress().Menu(settings =>
       {
           settings.Name = "toolBarMenu";
           settings.ItemAutoWidth = false;
           settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
           settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
           settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
           settings.Items.Add(item =>
      {
          item.Name = "btnSave";
          item.Text = "保存";
          item.ClientEnabled = true;
          item.Image.Url = Url.Content("~/Content/ControlImages/filesave.png");
          
      });
           settings.Items.Add(item =>
           {
               item.Name = "btnAddSame";
               item.Text = "增加同级";
               item.ClientEnabled = true;
               item.Image.Url = Url.Content("~/Content/ControlImages/addSame.png");
               
           });
           settings.Items.Add(item =>
           {
               item.Name = "btnAddNext";
               item.Text = "增加下级";
               item.ClientEnabled = true;
               item.Image.Url = Url.Content("~/Content/ControlImages/addNext.png");

           });
           settings.Items.Add(item =>
           {
               item.Name = "btnSeqSameLevel";
               item.Text = "同级部门排序";
               item.ClientEnabled = true;
               item.Visible = ViewData["hdMethod"] == null ? true : false;
               item.Image.Url = Url.Content("~/Content/ControlImages/move.png");

           });
           settings.Items.Add(item =>
           {
               item.Name = "btnDelete";
               item.Text = "删除";
               item.ItemStyle.ForeColor = System.Drawing.Color.Red;
               item.ClientEnabled = true;
               item.Image.Url = Url.Content("~/Content/ControlImages/cancel.png");

           });
           settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
           settings.ItemLinkMode = ItemLinkMode.ContentBounds;
       }).GetHtml()
        </div>
 
        <table class="tableForm">
            <tr>
                <th>
                    部门编号:</th>
                <td class="tdClass">
                    @Html.DevExpress().TextBox(settings =>
           {
               settings.Name = "tbDeptNo";
               settings.Width = 200;
               settings.Text = Model.FDeptNo;
               settings.Enabled = (bool)@ViewData["bl_deptno"];
               
               settings.Properties.ValidationSettings.EnableCustomValidation = true;
           }).GetHtml()
                    @Html.Hidden("hidDeptNo", Model.FDeptNo)
                </td>
                <th>
                    部门名称:</th>
                <td class="tdClass">
                    @Html.DevExpress().TextBox(settings =>
           {
               settings.Name = "tbDeptName";
               settings.Width = 200;
               settings.Text = Model.FDeptName;
               settings.Properties.ValidationSettings.EnableCustomValidation = true;
           }).GetHtml()</td>
            </tr>
            <tr>
                <th>
                    上级目录:</th>
                <td class="tdClass">
                    @Html.DevExpress().TextBox(settings =>
           {
               settings.Name = "tbParentDeptName";
               settings.Width = 200;
               settings.Enabled = false;
               settings.Text = Model.FParentDeptName;
           }).GetHtml()
                    @Html.Hidden("hidParentDeptNo", Model.FParentDeptNo)
                </td>
                <th>
                    部门属性:</th>
                <td class="tdClass">
                    @Html.DevExpress().ComboBox(
            settings =>
            {
                settings.Name = "ddlDeptProp";
                settings.Properties.DropDownStyle = DropDownStyle.DropDownList;
            }).BindList(new List<SelectListItem> { new SelectListItem { Text = "领导部门", Value = "1" }, new SelectListItem { Text = "综合部门", Value = "2" }, new SelectListItem { Text = "业务部门", Value = "3" }, new SelectListItem { Text = "虚拟部门", Value = "9" } }).Bind(Model.FDeptProp).GetHtml()
                </td>
            </tr>
            <tr>
                <th>
                    是否派出机构:</th>
                <td class="tdClass">
                    @Html.DevExpress().RadioButtonList(settings =>
       {
           settings.Name = "rbIsAgency";
           settings.Properties.RepeatLayout = System.Web.UI.WebControls.RepeatLayout.Table;
           settings.Properties.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
           settings.Properties.RepeatColumns = 2;

       }).BindList(new List<SelectListItem> { new SelectListItem { Text = "是", Value = "Y" }, new SelectListItem { Text = "否", Value = "N" } }).Bind(Model.FIsAgency).GetHtml()
                </td>
                <th>
                    分管领导:</th>
                <td class="tdClass">
                @Html.DevExpress().ButtonEdit(settings =>
                   {
                       settings.Name = "tbChargeLeader";
                       settings.Width = 220;
                       settings.ReadOnly = true;
                       settings.Properties.Buttons.Add("选择");
                       settings.Properties.ClientSideEvents.ButtonClick = "ChargeLeader_ButtonClick";
                       settings.Properties.ClientSideEvents.Validation = "function(s,e){notEmptyValidation(s,e,'分管领导')}";
                   }).Bind(Model.FChargeLeaderName).GetHtml()



                  @*  @Html.DevExpress().TextBox(settings =>
           {
               settings.Name = "tbChargeLeader";
               settings.Width = 200;
               settings.Enabled = false;
               settings.Text = Model.FChargeLeader;
               settings.ControlStyle.CssClass = "left";
               settings.Properties.EnableClientSideAPI = true;
           }).Bind(Model.FChargeLeaderName).GetHtml()
                    @Html.DevExpress().Button(settings =>
          {
              settings.Name = "btnSelect";
              settings.Text = "选择";
              settings.ControlStyle.CssClass = "button";
              settings.ClientSideEvents.Click = "function(){pcModalMode.Show();}";
          }).GetHtml()*@
                    @Html.Hidden("hidChargeLeader", Model.FChargeLeader)
                </td>
            </tr>

            <tr style="display:none;">
                <th>
                    </th>
                <td class="tdClass">
                     @Html.DevExpress().CheckBox(
                    settings =>
                    {
                        settings.Name = "FIsReportPlanSummary";
                        settings.Checked = Model.FIsReportPlanSummary == "Y" ? true : false;
                        settings.Text = "需要上报计划总结";
                    }).GetHtml()
                </td>
                <th>
                    </th>
                <td class="tdClass">
                 @Html.DevExpress().CheckBox(
                    settings =>
                    {
                        settings.Name = "FIsCheckSystem";
                        settings.Checked = Model.FIsCheckSystem == "Y" ? true : false;
                        settings.Text = "参与网上考核";
                    }).GetHtml()

                </td>
            </tr>

            <tr>
                <th>
                    显示顺序:</th>
                <td class="tdClass">
                    @Html.DevExpress().TextBox(settings =>
           {
               settings.Name = "tbSeq";
               settings.Width = 200;
               settings.Text = Model.FSeq.ToString();
               settings.Properties.ValidationSettings.EnableCustomValidation = true;
           }).GetHtml()
                </td>
                <th>
                    单位简称:</th>
                <td class="tdClass">
                    @Html.DevExpress().TextBox(settings =>
           {
               settings.Name = "FDeptShorName";
               settings.Width = 200;
               settings.Text = Model.FDeptShorName;
               settings.Properties.ValidationSettings.EnableCustomValidation = true;
           }).GetHtml()
                </td>
            </tr>
        </table>
    
        <br />
      
    
        @Html.DevExpress().PopupControl(
    settings =>
    {
        settings.Name = "pcModalMode";
        settings.Width = 300;
        settings.Height = 430;
        settings.AllowDragging = true;
        settings.CloseAction = CloseAction.CloseButton;
        settings.EnableAnimation = false;
        settings.HeaderText = "人员选择";
        settings.Modal = true;
        settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
        settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
        //settings.ClientSideEvents.CloseUp = "function(s, e){ ASPxClientEdit.ClearEditorsInContainer(null, '', true); }";
        //settings.ContentUrl = "/Admin/Dept/EmpData";

        settings.ShowFooter = true;
        settings.SetFooterTemplateContent(s =>
        {
            ViewContext.Writer.Write("<table align='center'><tr><td>");
            @Html.DevExpress().Button(footBtnSettings =>
            {
                footBtnSettings.Name = "btnOK";
                footBtnSettings.Text = "确定";
                footBtnSettings.ClientSideEvents.Click = "function(s,e){popContent.OK()}";
                footBtnSettings.Images.Image.Url = Url.Content("~/Content/ControlImages/ok.png");
                footBtnSettings.CausesValidation = false;
            }).GetHtml();
            ViewContext.Writer.Write("</td><td>");
            @Html.DevExpress().Button(footBtnSettings =>
            {
                footBtnSettings.Name = "btnCancel";
                footBtnSettings.Text = "取消";
                footBtnSettings.ClientSideEvents.Click = "EmpCancel";
                footBtnSettings.Images.Image.Url = Url.Content("~/Content/ControlImages/no.png");
                footBtnSettings.CausesValidation = false;
            }).GetHtml();
            ViewContext.Writer.Write("</td></tr></table>");

        });
        settings.SetContent(() =>
        {
            ViewContext.Writer.Write("<iframe  id='popContent' name='popContent' style='width:100%;height:330px' frameborder='0' src='" + Url.Action("EmpData", "Dept") + "'></iframe>");
        });

    }).GetHtml()
    
       
    
        @Html.Partial("PositionGrid", @ViewData["position"])

    
        @Html.DevExpress().PopupControl(
    settings =>
    {
        settings.Name = "positionModalMode";
        settings.Width = 360;
        settings.Height = 230;
        settings.AllowDragging = true;
        settings.CloseAction = CloseAction.CloseButton;
        settings.EnableAnimation = false;
        settings.HeaderText = "岗位";
        settings.Modal = true;
        settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
        settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
        //settings.ContentUrl = "/Admin/Dept/PositionEdit";
        settings.ShowFooter = true;
        settings.SetFooterTemplateContent(s =>
        {
            ViewContext.Writer.Write("<table align='center'><tr><td>");
            @Html.DevExpress().Button(footBtnSettings =>
            {
                footBtnSettings.Name = "btnPositionOK";
                footBtnSettings.Text = "确定";
                footBtnSettings.ClientSideEvents.Click = "function(s,e){popPositionContent.OK()}";
                footBtnSettings.Images.Image.Url = Url.Content("~/Content/ControlImages/ok.png");
                footBtnSettings.CausesValidation = false;
            }).GetHtml();
            ViewContext.Writer.Write("</td><td>");
            @Html.DevExpress().Button(footBtnSettings =>
            {
                footBtnSettings.Name = "btnPositionCancel";
                footBtnSettings.Text = "取消";
                footBtnSettings.ClientSideEvents.Click = "positonCancel";
                footBtnSettings.Images.Image.Url = Url.Content("~/Content/ControlImages/no.png");
                footBtnSettings.CausesValidation = false;
            }).GetHtml();
            ViewContext.Writer.Write("</td></tr></table>");

        });
        settings.SetContent(() =>
        {
            ViewContext.Writer.Write("<iframe  id='popPositionContent' name='popPositionContent' style='width:100%;height:150px' frameborder='0' ></iframe>");
        });

    }).GetHtml()
    
    
    }

</body>
</html>
